# 水桶8L满 5L空 3L空，要把这8升水分成4L和4L
# 索引0,1,2的位置分别对应8L桶 5L桶 3L桶
start = [8, 0, 0]


def dump(state):
    state_dic = {}
    state_dic[8] = state[0]
    state_dic[5] = state[1]
    state_dic[3] = state[2]
    may_state = []
    for bucket in state_dic:
        # bucket为桶的容量,water为对应桶当前状态下的水量
        water = state_dic.pop(bucket)
        other_dic = state_dic.copy()
        # 判断倒水的桶中有水
        if water > 0:
            for other_bucket in other_dic:
                # 判断接水的桶水不满
                if other_bucket > state_dic[other_bucket]:
                    # 倒水的两种情况：
                    # 1.倒入水大于剩余容量
                    space = other_bucket - state_dic[other_bucket]
                    if water > space:
                        state_dic[other_bucket] = other_bucket
                        state_dic[bucket] = water - space
                    # 2.倒入水小于剩余容量
                    if water <= space:
                        state_dic[bucket] = 0
                        state_dic[other_bucket] += water
                    may_state.append([state_dic[8], state_dic[5], state_dic[3]])
                    state_dic[8] = state[0]
                    state_dic[5] = state[1]
                    state_dic[3] = state[2]
                    # print(state_dic)
        state_dic[bucket] = water
    # 倒水（6种情况）
    # 返回可能的状态列表
    print(may_state)
    return may_state


# 记录所有状态
all_state = []
# 记录倒过水的状态
recode_state = [[8, 0, 0]]


def move(now_state):
    if now_state == [4, 4, 0]:
        print('完成')
        print(recode_state)
        # all_state.clear()
        return
    state_list = dump(now_state)
    # 遍历可能的状态列表

    for state in state_list:
        if state not in all_state or state == [4, 4, 0]:
            all_state.append(state)
            new_state = state
            recode_state.append(state)
            move(new_state)
            recode_state.remove(state)
    # print(all_state)
    return


move([8, 0, 0])
